=<template>
  <div class="keyexam" v-loading='loading' >
    <div class='bts-group'>
      <el-button v-for='(item,index) in uploadType'
                  :key='index'
                  @click='goPath(item.path)'
                  :class='activeIndex2==index ? "sure":""'>{{item.name}}</el-button>
    </div>
    <Table :data1='data1' :data2='data2' :data3='data3'></Table>
    <div class="bts" >

      <el-button class='sure' @click="saveData(0)">保存</el-button>
      <el-button class='sure' 
                  @click="saveData(1)">下一步</el-button>
    </div>
  </div>
</template>

<script>
import Table from './common/table2'
export default {
  components: {
   Table
  },
  data () {
    return {
      data1:[],
      data2:[],
      data3:[],
      tit:'',
      leftImg:'',
      loading:false,
      reviewTemplateName:'',
      varname:"",
      planSummaryId:'',
      signImg:'',
      autograph:'',
      radios: [1, 2, 3],
      uploadType: [
        {
          name: '形式评审',
          path: 'situationexam2'
        },
        {
          name: '要素评审',
          path: 'keyexam2'
        },
        {
          name: '附件要素评审',
          path: 'powerexam2'
        },
        {
          name: '个人评审意见',
          path: 'personexam2'
        }
      ],

      activeIndex2: 1,
    };
  },
  mounted(){
     this.getData()
     this.signImg = localStorage.signImg
      this.autograph =localStorage.autograph
  this.$nextTick(()=>{
      document.querySelector('.left-box').style.height='4661px'
    })
  },

  methods:{
    goPath(path){
this.saveData(2,path)
    },
    getData(){
      this.loading=true
       this.postData(0,6)
        .then( res=> {
           this.loading=false
            if (res.data.meta.success) {
                this.varname = res.data.data.companyName
               res.data.data.list.map((item,index)=>{
                   item.result=item.selectResult
                })

                var obj = {
                  reviewContent: [this.signImg],
                  reviewItemOne: "评审专家签字",
                  reviewMethod: "",
                  tableType: "6",
                  flag:0,
                }
               this.data1 = res.data.data.list.splice(0,20)
               this.data2 = res.data.data.list.splice(0,10)
               this.data3 = res.data.data.list
               
                this.data1.push({
                    reviewContent : '',
                    reviewItemOne: "注：“＊”代表应急预案的关键要素。",
                    reviewMethod: "",
                    tableType: "6",
                    flag:1,
                })
                this.data2.push({
                   reviewContent: '',
                   reviewItemOne: "注：“＊”代表应急预案的关键要素。如果专项应急预案作为综合应急预案的附件，综合应急预案已经明确的要素，专项应急预案可省略。",
                    reviewMethod: "",
                    tableType: "6",
                    flag:1,
                })
                this.data3.push({
                   reviewContent: '',
                   reviewItemOne: "注：“＊”代表应急预案的关键要素。现场处置方案落实到岗位每个人，可以只保留应急处置。",
                    reviewMethod: "",
                    tableType: "6",
                    flag:1,
                })
                this.data1.push(obj)
                 this.data2.push(obj)
                 this.data3.push(obj)     

           
            } else {
               this.$message.warning(res.data.meta.message)
            }
        })
        .catch(function (res) {
           console.log(res)
        })
    },
    saveData(n,path){
      let list=[]
      for(var i=1;i <4;i++){
        this['data'+i].map((item,index)=>{
          if(index < ( this['data'+i].length-2)){
              list.push({
                    tableId:item.id,
                    result:item.result 
              })
          }
        })
      }
       var flag = list.every(item=>{
         return (item.result!='' && item.result)
        })
      if(!flag){
         this.$message.warning('请选择完毕后再保存')
      }else{
       
      this.postData(2,6,list,this.autograph)
          .then(res => {
            if (res.data.meta.success) {
              if(n==1){
                 this.$router.push('powerexam2')
              }else if(n==2){
               this.$router.push(path)
              }else{
                
              this.$message.success(res.data.meta.message)
              }
            } else {
              this.$message.warning(res.data.meta.message)
            }
          })
          .catch(response => {
            console.log(response);
          });
      }

    }
  }
}
</script>